<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .main {
            padding: 10px 15px;
        }
        .main ul li {
            margin-bottom: 10px;
        }
        .main ul li:last-child {
            margin-bottom: 0;
        }
        .main ul li .li_box {
            height: 68px;
            border-radius: 10px;
            display: -webkit-box;
            display: -webkit-flex;
            position: relative
        }
        .main ul li .li_box .li_boxl {
            width: 70px;
            height: 68px;
            line-height: 68px;
            background-color: #cdcdcd;
            font-size: 24px;
            color: #fff;
            text-align: center;
            border-top-left-radius: 10px;
            border-bottom-left-radius: 10px;
        }
        .main ul li.active .li_box .li_boxl {
            background-color: #e62442;
        }
        .main ul li .li_box .li_boxl span {
            font-size: 15px;
            vertical-align: top;
            margin-top: -3px;
        }
        .main ul li .li_box .li_boxc {
            width: 0;
            height: 68px;
            background-color: #fff;
            padding-left: 14px;
            padding-right: 5px;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            display: -webkit-box;
            -webkit-box-align: center;
        }
        .main ul li .li_box .li_boxc .title {
            font-size: 16px;
            color: #333;
            margin-bottom: 8px;
        }
        .main ul li .li_box .li_boxc .time {
            font-size: 12px;
            color: #999;
        }
        .main ul li .li_box .li_boxr {
            height: 68px;
            padding-right: 15px;
            background-color: #fff;
            display: -webkit-box;
            -webkit-box-align: center;
            border-top-right-radius: 10px;
            border-bottom-right-radius: 10px;
        }
        .main ul li .li_box .li_boxr img {
            height: 13px;
            display: block;
        }
        .circle_box .circle1 {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background-color: #f8f8f8;
            position: absolute;
            left: 64px;
            top: -6px;
            z-index: 99;
        }
        .circle_box .circle2 {
            width: 5px;
            height: 5px;
            border-radius: 50%;
            background-color: #f8f8f8;
            position: absolute;
            left: 68px;
            top: 16px;
            z-index: 99;
        }
        .circle_box .circle3 {
            width: 5px;
            height: 5px;
            border-radius: 50%;
            background-color: #f8f8f8;
            position: absolute;
            left: 68px;
            top: 0;
            bottom: 0;
            margin: auto;
            z-index: 99;
        }
        .circle_box .circle4 {
            width: 5px;
            height: 5px;
            border-radius: 50%;
            background-color: #f8f8f8;
            position: absolute;
            left: 68px;
            bottom: 16px;
            z-index: 99;
        }
        .circle_box .circle5 {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background-color: #f8f8f8;
            position: absolute;
            left: 64px;
            bottom: -6px;
            z-index: 99;
        }
        .loading{
            color: #ccc;
            text-align: center;
            line-height: 25px;
            display: none;
        }
        .without_data{
            display: none;
            color:#ccc;
            text-align:center;
            padding-top: 15px;
        }
    </style>
</head>
<body>
    <div class="main">
        <p class="without_data">暂无优惠</p>
        <ul id="data_ul">
<!--             <li class="active">
                <div class="li_box">
                    <div class="li_boxl"><span>$</span>3</div>
                    <div class="li_boxc">
                        <div>
                            <div class="title">商家名称</div>
                            <div class="time">2017.09.14-2017.09.16</div>
                        </div>
                    </div>
                    <div class="li_boxr">
                        <img src="../image/right.png">
                    </div>
                    <div class="circle_box">
                        <div class="circle1"></div>
                        <div class="circle2"></div>
                        <div class="circle3"></div>
                        <div class="circle4"></div>
                        <div class="circle5"></div>
                    </div>
                </div>
            </li> -->

        </ul>
        <div class="loading">loading...</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/script.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script id="dataTpl" type="text/x-dot-template">
    {{ for(var i=0;i<it.length;i++){ }}
            <li onclick="fnOpenSeller({{=it[i]['shop_id']}});" tapmode>
                <div class="li_box">
                    <div class="li_boxl"><span>$</span>{{=it[i]['price']}}</div>
                    <div class="li_boxc">
                        <div>
                            <div class="title">{{=it[i]['name']}}</div>
                            <div class="time">{{=it[i]['begin_time']}}-{{=it[i]['end_time']}}</div>
                        </div>
                    </div>
                    <div class="li_boxr">
                        <img src="../image/right.png">
                    </div>
                    <div class="circle_box">
                        <div class="circle1"></div>
                        <div class="circle2"></div>
                        <div class="circle3"></div>
                        <div class="circle4"></div>
                        <div class="circle5"></div>
                    </div>
                </div>
            </li>
    {{ }; }}
</script>
<script type="text/javascript">
    apiready = function(){
        p = 1;
        canLoad = true;
        user = $api.getStorage('user_data');
        openLoading();
        fnGetTicket();

        //上拉加载
        api.addEventListener({
            name:'scrolltobottom',
            extra:{
                threshold:0            //设置距离底部多少距离时触发，默认值为0，数字类型
            }
        }, function(ret, err){
            if(canLoad) {
                p++;
                if($(window).scrollTop()) {
                    $(".loading").show();
                }
                fnGetTicket(2);
            }
        });

        //下拉刷新
        api.setCustomRefreshHeaderInfo({
            bgColor: '#f8f8f8',
            loadAnimInterval:60,
            image: {
               pull: pullArr,
               load: loadArr
            }
        }, function(ret, err) {
            p = 1;
            fnGetTicket(1);
        });

        //监听优惠卷变化
        api.addEventListener({
            name: 'ticketChangeEvent'
        }, function(ret, err) {
            if (ret) {
                p = 1;
                fnGetTicket(1);
            }
        });
    };

    function fnGetTicket(type) {
        if(canLoad == false) {
            return;
        }
        canLoad = false;
        api.ajax({
            url: rootPath+'/api/user/ticket',
            method: 'get',
            cache: true,
            data: {
                values: { 
                    p:p,
                    uid : user.id,
                    token:user.token,
                    status : 3
                },
            }
        }, function(ret, err) {
            //type=1 下拉刷新，清除原来数据
            if(type == 1) {
                $('#data_ul').empty();
            }
            if (ret) {
                if(ret.status == 200) {
                    $('.without_data').hide();
                    $('.title_p').show();
                    appendDotData(ret.data,'dataTpl','data_ul',true);
                }else {
                    if(p == 1) {
                        $('.without_data').show();
                    }
                }
            } else {
                showError(err.code,err.msg)
            }
            if(type == 1) {
                // 是下拉刷新的，要收回
                api.refreshHeaderLoadDone();
            }
            if(type == 2) {
                //上拉给点假时间,好看些         
                setTimeout(function(){
                    $(".loading").hide();
                },1000);
                setTimeout(function(){
                    canLoad = true;
                },1100)
            }else {
                $('.loading').hide();
                canLoad = true;
            }
            closeLoading();
        });
    }
</script>
</html>